#python3
#钉钉，微信群日报
from pymouse import PyMouse
from pykeyboard import PyKeyboard
import pyperclip
import time,datetime
import win32gui

def create_report():
    now = datetime.datetime.now()
    now1 = now+datetime.timedelta(days=-1)
    mon1 = now1.month
    day1 = now1.day
    now2 = now
    mon2 = now2.month
    day2 = now2.day
    reportStr = f'''
《XXXX单位{mon2}月{day2}日报》{mon1}月{day1}日8点-{mon2}月{day2}日8点
情况1：无
情况2：无
情况3：无
        '''
    return reportStr

def set_window_top(windowStr):
    hwnd = win32gui.FindWindow(0, windowStr)
    if not hwnd:
        print("[!] 窗口找不到，请确认窗口句柄名称：【%s】" % windowStr )
        return False
    # 窗口显示最前面
    win32gui.SetForegroundWindow(hwnd)
    return True

windowStr = '钉钉'
if set_window_top(windowStr) == False:
    exit(-1)

m = PyMouse()
k = PyKeyboard()

#x_dim, y_dim = m.screen_size()
#print("%d,%d"%(x_dim, y_dim))
#m.click(1200, 700, 1)

#向剪贴板写入报告
pyperclip.copy(create_report())
time.sleep(2)

#点击输入窗口
m.click(700, 500, 1)

#模拟键盘点击ctrl+v，实现字符串复制功能
k.press_key(k.control_key)
k.tap_key('v')
k.release_key(k.control_key)#此时，汉字已经被复制到输入框了
time.sleep(2)

#回车键发送
#若是其它键，需修改
k.press_key(k.enter_key)
